#include <stdio.h>

#define min(a,b) (((a) < (b)) ? (a) : (b))

int main(int argc, char const *argv[])
{
    int lines[1024] = { 0 }, rows[1024] = { 0 }, lines_out[1024] = { 0 }, rows_out[1024] = { 0 };
    int m, n, k, l, d, x, y, p, q;
    int i, j, max, max_index, is_head;

    scanf("%d%d%d%d%d", &m, &n, &k, &l, &d);
    for (i = 0; i < d; i++)
    {
        scanf("%d%d%d%d", &x, &y, &p, &q);
        if (x == p)
        {
            rows[min(y, q)]++;
        }
        else
        {
            lines[min(x, p)]++;
        }
    }

    if (k > 0)
    {
        for (i = 0; i < k; i++)
        {
            max = 0, max_index = -1;
            for (j = 0; j < 1024; j++)
            {
                if (lines[j] > max)
                {
                    max = lines[j];
                    max_index = j;
                }
            }
            if (max_index == -1)
            {
                break;
            }
            lines_out[max_index] = 1;
            lines[max_index] = 0;
        }
    }
    is_head = 1;
    for (i = 0; i < 1024; i++)
    {
        if (lines_out[i])
        {
            printf(is_head ? "%d" : " %d", i);
            is_head = 0;
        }
    }
    printf("\n");
    if (l > 0)
    {
        for (i = 0; i < l; i++)
        {
            max = 0, max_index = -1;
            for (j = 0; j < 1024; j++)
            {
                if (rows[j] > max)
                {
                    max = rows[j];
                    max_index = j;
                }
            }
            if (max_index == -1)
            {
                break;
            }
            rows_out[max_index] = 1;
            rows[max_index] = 0;
        }
    }
    is_head = 1;
    for (i = 0; i < 1024; i++)
    {
        if (rows_out[i])
        {
            printf(is_head ? "%d" : " %d", i);
            is_head = 0;
        }
    }
    
    return 0;
}

